<template>
  <div class="fen">
    <!-- 导航头部 -->
    <van-nav-bar title="搜索" fixed />
    <!-- 商品列表 -->
    <div class="box">
      <div class="left">
        <ul>
          <li
            @click="itemList(index)"
            :class="current == index ? 'red' : ''"
            v-for="(item, index) in list"
            :key="item.id"
          >
            {{ item.name }}
          </li>
        </ul>
      </div>
      <div class="right">
        <div class="banner">
          <img :src="xfq.banner_url" alt="" />
        </div>
        <div class="title">—— {{ xfq.name }}分类 ——</div>
        <div class="show">
          <ul>
            <router-link
              :to="`/fenzi?id=${item.id}&index=${index}`"
              class="timearr"
              v-for="(item, index) in xfqyyds"
              :key="item.id"
              tag="p"
            >
              <img :src="item.wap_banner_url" alt="" />
              <p>{{ item.name }}</p>
            </router-link>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { indexaction, currentaction } from "@/api/分类/fen.js";
export default {
  name: "Fen",
  data() {
    return {
      // 侧边主导航
      list: [],
      current: 0,
      // 右边二级次级导航
      xfqyyds: [],
      // 二级导航大图
      xfq: [],
    };
  },
  methods: {
    // 分类页面初次进来加载的左侧导航
    itemList(index) {
      this.current = index;
      currentaction({
        params: {
          id: this.list[this.current].id,
        },
      }).then((res) => {
        this.xfqyyds = res.data.data.currentOne.subList;
      });
    },
  },
  // 左侧导航点击得到右侧分导航数据
  async created() {
    var res = await indexaction();
    // console.log(res);
    this.list = res.data.categoryList;
    // .then((res) => {
    //   console.log(res);
    //   this.list = res.data.categoryList;
    // });
    console.log(this.list[this.current].id);
    var res2 = await currentaction({
      params: {
        id: this.list[this.current].id,
      },
    });
    // console.log(res2);
    this.xfq = res2.data.data.currentOne;
    this.xfqyyds = res2.data.data.currentOne.subList;
  },
};
</script>

<style lang="less" scoped>
.fen {
  background-color: rgb(253, 253, 253);
  .box {
    margin-top: 48px;
    display: flex;
    justify-content: space-between;
    // align-items: center;
    .left {
      width: 82px;
      ul {
        list-style: none;
        li {
          text-align: center;
          width: 80px;
          line-height: 50px;
          font-style: 12px;
          border-left: 2px solid rgb(0, 255, 21);
        }
        .red {
          border-left: 2px solid red;
          font-size: 18px;
          color: red;
        }
      }
    }
    .right {
      flex: 1;
      .banner {
        height: 123px;
        width: 100%;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .title {
        width: 100%;
        font-style: 20px;
        padding: 15px 0;
        font-weight: 700;
        text-align: center;
      }
      .show {
        margin-top: 5px;
        ul {
          list-style: none;
          display: flex;
          justify-content: flex-start;
          align-items: center;
          flex-wrap: wrap;
          .timearr {
            width: 33%;
            height: 96px;
            text-align: center;
            margin-bottom: 5px;
            img {
              width: 100%;
              height: 80%;
            }
          }
        }
      }
    }
  }
}
</style>